//
//  KKBuyVideoVC.m
//  DoMi
//
//  Created by 康凯 on 2016/11/16.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKBuyVideoVC.h"
#import "KKBuyVideoCell.h"
#import "KKMyHttp.h"
#import "KKVideoDetailController.h"
#import "KKCollectVideoM.h"

@interface KKBuyVideoVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic)NSArray *buyDatas;
@end

@implementation KKBuyVideoVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setNavBlack];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title=@"我购买的视频";
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    [self.tableView registerNib:[UINib nibWithNibName:@"KKBuyVideoCell" bundle:nil] forCellReuseIdentifier:@"KKBuyVideoCell"];
    
    [self getMyBuyVideo];
}

#pragma mark tableview代理
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    KKBuyVideoCell *buy=(KKBuyVideoCell *)cell;
    [buy initData:self.buyDatas[indexPath.row]];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.buyDatas.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [tableView dequeueReusableCellWithIdentifier:@"KKBuyVideoCell"];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 75;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    KKCollectVideoM *buyInfo=self.buyDatas[indexPath.row];
    KKVideoDetailController *detail=[[KKVideoDetailController alloc] init];
    detail.videoId=buyInfo.videoid;
    [self.navigationController pushViewController:detail animated:YES];
}

#pragma mark 接口--获取购买视频
-(void)getMyBuyVideo{
    [self showDialog];
    [KKMyHttp getMyBuyList:@"1" success:^(id data) {
        self.buyDatas=data;
        [self.tableView reloadData];
        [self dismissDialog];
    } failure:^(NSError *error) {
        [self dismissDialog];
    }];
}
@end
